package com.bjsxt.controller.system;

import com.bjsxt.aspectj.annotation.Log;
import com.bjsxt.aspectj.enums.BusinessType;
import com.bjsxt.dto.CheckItemDto;
import com.bjsxt.service.CheckItemService;
import com.bjsxt.utils.ShiroSecurityUtils;
import com.bjsxt.vo.AjaxResult;
import com.bjsxt.vo.DataGridView;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author:liao
 * @Description:TODO 检查项目
 * @date:2020/12/17
 */
@RestController
@RequestMapping("system/checkItem")
public class CheckItemController {
    @Autowired
    private CheckItemService checkItemService;

    //分页查询
    @GetMapping("listCheckItemForPage")
    public AjaxResult listCheckItemForPage(CheckItemDto checkItemDto){
        DataGridView dataGridView = checkItemService.listCheckItemPage(checkItemDto);
        return AjaxResult.success("查询成功",dataGridView.getData(),dataGridView.getTotal());
    }

    // 添加
    @PostMapping("addCheckItem")
    @Log(title = "添加检查项目",businessType = BusinessType.INSERT)
    public AjaxResult addCheckItem(@Validated CheckItemDto checkItemDto){
        checkItemDto.setSimpleUser(ShiroSecurityUtils.getCurrentSimpleUser());
        return AjaxResult.toAjax(checkItemService.addCheckItem(checkItemDto));
    }

    // 修改
    @PutMapping("updateCheckItem")
    @Log(title = "修改检查项目",businessType = BusinessType.UPDATE)
    public AjaxResult updateCheckItem(@Validated CheckItemDto checkItemDto){
        checkItemDto.setSimpleUser(ShiroSecurityUtils.getCurrentSimpleUser());
        return AjaxResult.toAjax(checkItemService.updateCheckItem(checkItemDto));
    }

    // 删除
    @DeleteMapping("deleteCheckItemByIds/{checkItemId}")
    @Log(title = "删除检查项目",businessType = BusinessType.DELETE)
    public AjaxResult deleteCheckItemByIds(@PathVariable Long[] checkItemId){
        return AjaxResult.toAjax(checkItemService.deleteCheckItemByIds(checkItemId));
    }

    // 根据id查询
    @GetMapping("getCheckItemById/{checkItemId}")
    public AjaxResult getCheckItemById(@PathVariable Long checkItemId){
        return AjaxResult.success(checkItemService.getOne(checkItemId));
    }

    // 查询全部有效的项目
    @GetMapping("selectAllCheckItem")
    public AjaxResult selectAllCheckItem(){
        return AjaxResult.success(checkItemService.queryAllCheckItem());
    }
}
